#include "FrameTab.h"
#include "ToolPane.h"
#include "FrameView.h"
#include <wx/file.h>
//(*InternalHeaders(FrameTab)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(FrameTab)
//*)

BEGIN_EVENT_TABLE(FrameTab,wxPanel)
	//(*EventTable(FrameTab)
	//*)
	EVT_SIZE(FrameTab::OnSize)
END_EVENT_TABLE()

FrameTab::FrameTab(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
    m_pAuiNoteBook = NULL;
	//(*Initialize(FrameTab)
	Create(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id"));
	//*)
	m_pAuiNoteBook = new wxAuiNotebook(this, wxID_ANY, wxPoint(8,8), wxSize(320,376), wxAUI_NB_DEFAULT_STYLE|wxAUI_NB_WINDOWLIST_BUTTON);
}

void FrameTab::OnSize(wxSizeEvent &ev)
{
    wxSize size = GetClientSize();
    size.SetWidth(size.GetWidth() - 5);

    if(m_pAuiNoteBook != NULL)
        m_pAuiNoteBook->SetSize(size);
}

FrameTab::~FrameTab()
{
	//(*Destroy(FrameTab)
	//*)
}

SFrame *FrameTab::GetSelFrame()
{
    if(m_pAuiNoteBook->GetPageCount() <= 0)
        return NULL;
    FrameView *pSel = (FrameView*)m_pAuiNoteBook->GetPage(m_pAuiNoteBook->GetSelection());
    if(pSel == NULL)
        return NULL;
    SFrame *pFrame = pSel->GetFrame();
    if(pFrame->m_imageList.size() > 0)
        return pFrame;
    return NULL;
}

void FrameTab::AddFrameTab(wxString &fileName)
{
    FrameView *pFrameView = new FrameView(m_pAuiNoteBook,wxID_ANY);
    wxFile file(fileName,wxFile::read);
    ReadFrame(file,GetPath(fileName),*pFrameView->GetFrame());
    wxString name = GetFileName(fileName);
    m_pAuiNoteBook->AddPage(pFrameView,name);
}
